<template>
  <a-modal v-model:visible="visible" title="编辑用户" :footer="null">
    <div class="py-8">
      <this-form @finished="finished" ref="formRef" />
    </div>
  </a-modal>
</template>
  <script lang="ts">
import { defineComponent, ref, nextTick } from 'vue';
import thisForm from './form.vue';
import { defHttp } from '/@/utils/http/axios';
import { message } from 'ant-design-vue';

export default defineComponent({
  components: { thisForm },
  setup(props, { emit }) {
    const visible = ref<boolean>(false);
    const formRef = ref<any>();
    let id;
    const open = (row) => {
      id = row.id;
      visible.value = true;

      nextTick(() => {
        formRef.value.setForm(row);
      });
    };

    const finished = (event) => {
      visible.value = false;
      defHttp
        .post({
          url: '/user/update',
          params: {
            id,
            username: event.username,
            password: event.password,
            name: event.realname,
            rId: event.role,
            comment: event.remark,
          },
        })
        .then((res) => {
          message.success('修改成功');
          emit('edited');
        });
      // emit(isEdit.value ? 'edited' : 'added', event);
    };

    return {
      visible,
      finished,
      open,
      formRef,
    };
  },
});
</script>
  
  